package br.com.musclebook.service;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;

import br.com.musclebook.entity.Routine;

@Stateless
public class RoutineService {

    @Inject
    private RoutineDAO routineDAO;

    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public Routine find(Long id) {
	return this.routineDAO.find(id);
    }

    public Routine insert(Routine routine) {
	return this.routineDAO.insert(routine);
    }

    public Routine update(Routine routine) {
	return this.routineDAO.update(routine);
    }

    public boolean updateRating(Long routineId, Integer newRate) {
	return this.routineDAO.updateRating(routineId, newRate);
    }
    
    public void delete(Long routineId) {
	this.routineDAO.delete(routineId);
    }

    public void setAsUserCurrent(Long routineId, Date start) {
	this.routineDAO.setAsUserCurrent(routineId, start);
    }
    
    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public List<Routine> list(Long userId) {
	return this.routineDAO.list(userId);
    }
}
